#include<iostream>
#include<string>
using namespace std;
typedef struct node *BTree;
struct node{
	char data;
	BTree lchild;
	BTree rchild;
};
BTree CreateBTree(string str,int i){
	BTree BT;
	BT=new node;
	if(i>str.size()-1||i<=0) return NULL;
	if(str[i]=='#') return NULL;
	BT->data=str[i];
	BT->lchild=CreateBTree(str,2*i);
	BT->rchild=CreateBTree(str,2*i+1);
	return BT; 
} 
void WPL(BTree BT,int &wpl,int h){
	if(BT==NULL) return;
	else
		if(BT->lchild==NULL&&BT->rchild==NULL){
			wpl+=h*(BT->data-'0');
			h=0;
		}
		h++;
	WPL(BT->lchild,wpl,h);
	WPL(BT->rchild,wpl,h);
}
int main(){
	string str;
	cin>>str;
	int i=1,wpl=0,h=0;
	BTree BT;
	BT=CreateBTree(str,i);
	WPL(BT,wpl,h);
	cout<<wpl; 
	return 0;
}
